<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>东东推登录</title>
<link href="../static/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="../static/css/common.css" rel="stylesheet">
<link href="../static/css/login.css" rel="stylesheet">
</head>
<body class="bodyb-color">
	
<!--隐藏域传值-->
<input type="hidden" id="token" />
	
<div class="container-fluid bodyb-color" >
	<div class=" container-fluid heardb-color">
		<div class="container" style="padding-top: 1.2%;padding-bottom: 1.3%;">
			<img src="../static/images/logo1.png" onclick="javascript:window.location.href='index.html'" />
			<p class="navbar-text navbar-right heard-text" onclick="javascript:window.location.href='login.html'">切换回登录 </p>
		</div>
	</div>
	<div class="container-fluid">
		<div class="login-con login" id="codePw">
			<p class="ddt-bt text-center"><strong style="font-size: 26px">找回密码</strong></p>
			<form class="form-horizontal">
			  <div class="form-group">
			  	<div class="col-sm-12">
			    	<input type="text" class="form-control" id="phone" placeholder="请输入手机号码" maxlength="11">
			    	<span id="helpBlock" class="help-block" style="height: 17px">　</span>
			    	<span class="glyphicon glyphicon-remove-sign form-control-feedback none error" aria-hidden="true"></span>
					<span class="glyphicon glyphicon-ok-sign form-control-feedback none success" aria-hidden="true"></span>
					
			    </div>
			  </div>
			  <div class="form-group">
					<div class="col-xs-8" style="padding-right: 2%;">
						<input type="text" class="form-control" id="code" placeholder="验证码" maxlength="6">
					</div>
					<div class="col-xs-4" style="padding-left: 2%;">
						<input type="button" class="btn btn-default ddt-btn code-btn" id="verCodeBtn" value="获取验证码" onclick="sendemail()" />
					</div>
					
				</div>
				<span id="helpBlock" class="help-block" style="height: 15px">　</span>
			  <button type="button" class="btn btn-default ddt-btn from-btn" id="getbackAgain" disabled="disabled">下一步</button>
			</form>
		</div>
		<div class="login-con login" id="resettingPw" >
			<p class="ddt-bt text-center"><strong>重置密码</strong></p>
			<form class="form-horizontal">
			  <div class="form-group">
			  	<div class="col-sm-12">
			    	<input type="password" class="form-control" id="userPwd" placeholder="输入新密码">
			    	<span id="helpBlock" class="help-block">　</span>
			    	<span class="glyphicon glyphicon-remove-sign form-control-feedback none error" aria-hidden="true"></span>
					<span class="glyphicon glyphicon-ok-sign form-control-feedback none success" aria-hidden="true"></span>
			    </div>
			  </div>
			  <div class="form-group">
			  	<div class="col-sm-12">
			    	<input type="password" class="form-control" id="againUserPwd" placeholder="确认新密码">
			    	<span id="helpBlock" class="help-block">　</span>
			    	<span class="glyphicon glyphicon-remove-sign form-control-feedback none error" aria-hidden="true"></span>
					<span class="glyphicon glyphicon-ok-sign form-control-feedback none success" aria-hidden="true"></span>
			    </div>
			  </div>
			  <button type="button" class="btn btn-default ddt-btn from-btn" id="chgpwdBtn">确认</button>
			</form>
		</div>
		<p class="text-center copyright">Copyright © 2014 -<h class='shi' style='font-size: 14px;'></h>  京ICP备18006432号-1</p>
	</div>
	
</div>
<script src="../static/js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="../static/bootstrap-3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../static/js/config.js" ></script>
<script>
	$(document).ready(function(){
		
		var myDate = new Date();
			//获取当前年
			var year=myDate.getFullYear();
			$('.shi').text(year)
			
		var phoneObj = $("#phone");
		var codeObj = $("#code");
		
		/*下一步按钮*/
		$("#getbackAgain").click(function(){
			console.log(phoneObj.val()+codeObj.val())
			$.ajax({
	    		type:"post",
	    		url:C.interface.forgetpwd,
	    		dateType:"json",
	    		data:{
		    		phone : phoneObj.val(),
		    		code : codeObj.val(),
		    		appId : "123456"
		    	},
	    		async:true,
	    		success:function(data){
		    		if(data.code == "10000"){
		    			$("#token").val(data.token);
		    			
		    			$("#codePw").hide();
						$("#resettingPw").show();
				    }else{
				    	errorHint(phoneObj,3,data.msg)
				    }
		    	}
	    	});
		});
		
		$("#chgpwdBtn").click(function(){
			var userPwd = $("#userPwd").val();
			var againUserPwd = $("#againUserPwd").val();
			/*判断两次密码是否相等*/
			if(userPwd == againUserPwd){
				
				successHint($("#userPwd"));
				successHint($("#againUserPwd"));
				
				/* 调用注册方法 */
				$.ajax({
		    		type:"post",
		    		url:C.interface.chgpwd,
		    		dateType:"json",
		    		data:{
			    		token : $("#token").val(),
			    		appId : "123456",
			    		newpwd : userPwd,
			    		confirmpwd : againUserPwd
			    	},
		    		async:true,
		    		success:function(data){
		    			/*手机号已经存在*/
			    		if(data.code == "10000"){
					    	window.location.href='login.html'; /*成功跳转*/
					    }else{
					    	errorHint(phoneObj,3,data.msg);
					    }
			    	}
		    	});
				
			}else{
				errorHint($("#userPwd"),1,"");
	    		errorHint($("#againUserPwd"),1,"");
			}
		});
	})
	
		
	/*验证码倒计时*/
	var countdown=60; 
	function sendemail(){
	    var obj = $("#verCodeBtn");
	    
	    var phone = $("#phone").val();
	    
	    var phoneObj = $("#phone") ;
	    
	    if(C.phoneReg.test(phone)){
	    	
	    	/*调用发送验证码接口*/
	    	$.ajax({
	    		type:"post",
	    		url:C.interface.code,
	    		dateType:"json",
	    		data:{
		    		phone : phone
		    	},
	    		async:true,
	    		success:function(data){
		    		if(data.code == "10000"){
		    		  successHint(phoneObj);
				      settime(obj);
				      $('#getbackAgain').removeAttr("disabled"); 
				    }else{
				    	errorHint(phoneObj,3,data.msg)
				    }
		    	}
	    	});
	    	
	    }else{
	    	//添加错误提示
	    	errorHint(phoneObj,2,"");
	    }
	    
	}
	function settime(obj) { //发送验证码倒计时
		
	    if (countdown == 0) { 
	        obj.attr('disabled',false); 
	        obj.val("获取验证码");
	        countdown = 60; 
	        return;
	    } else { 
	        obj.attr('disabled',true);
	        obj.val("重新发送(" + countdown + ")");
	        countdown--; 
	    } 
		setTimeout(function(){settime(obj)},1000) 
	}
	
	
	/*错误提示*/
	function errorHint(valStr,flag,msg){
		var valStrOjb = valStr.parent().parent(); 
		var valStrId = valStr.attr("id") ; 
		
		valStrOjb.removeClass("has-success");
		valStrOjb.find(".success").addClass("none");
    	valStrOjb.addClass("has-error");					
    	valStrOjb.find(".error").removeClass("none");
    	
    	if(flag==1){
		    valStrOjb.find(".help-block").text("两次密码不一致");
		}else if(flag==0){
			if(valStrId == "phone"){
				valStrOjb.find(".help-block").text("手机号不能为空");
			}else if(valStrId == "code"){
				valStrOjb.find(".help-block").text("验证码不能为空");
			}
    	}else if(flag==2){
    		valStrOjb.find(".help-block").text("手机号码格式错误");
    	}
    	else if(flag==3){
    		valStrOjb.find(".help-block").text(msg);
    	}
	}
	/*成功提示*/
	function successHint(valStr){
		var valStrOjb = valStr.parent().parent(); 
		valStrOjb.removeClass("has-error");
    	valStrOjb.find(".error").addClass("none");
    	valStrOjb.find(".help-block").text("　");
    	
    	valStrOjb.addClass("has-success");
    	valStrOjb.find(".success").removeClass("none");
    	valStrOjb.find(".help-block").text("　");
	}
	
</script>
</body>
</html>